package jsu.yym.tiktok.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements UserDetails {
    private String username;
    private String password;
    private Collection<? extends GrantedAuthority> authorities;

    // 其他可能的用户属性
//    private Long userId;
//    // ...

    //    public LoginUser(User user, Set<String> permissions) {
//        this.user = user;
//        this.permissions = permissions;
//    }

//    @JSONField(serialize = false)
//    private Set<SimpleGrantedAuthority> authorities;

//    public LoginUser(User user, String encode, List<GrantedAuthority> auths) {
//        this.user=user;
//    }


//    @Override
//    public Collection<? extends GrantedAuthority> getAuthorities() {
//        if (authorities!=null){
//            return authorities;
//        }
//        authorities = permissions.stream().
//                map(SimpleGrantedAuthority::new).
//                collect(Collectors.toSet());
//        return authorities;
//    }


    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
